home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: miker3@ix.netcom.com (Mike Rubenstein)
- Newsgroups: comp.lang.c
- Subject: Re: What the hell is THIS?!
- Date: Thu, 18 Jan 1996 01:21:42 GMT
- Organization: Netcom
- Message-ID: <30fd9e14.22385664@nntp.ix.netcom.com>
- References: <4d6rgh$rfu@abel.cc.sunysb.edu> <coc-1301960253420001@dal1498.computek.net> <821539645snz@genesis.demon.co.uk> <4dk45c$pdp@gryphon.phoenix.net>
- NNTP-Posting-Host: ix-dc6-05.ix.netcom.com
- X-NETCOM-Date: Wed Jan 17 5:21:37 PM PST 1996
- X-Newsreader: Forte Agent .99c/16.141
-
- brucew@phoenix.net (Bruce Wedding) wrote:
-
- > Lawrence Kirby <fred@genesis.demon.co.uk> wrote:
- >
- > >No, it is a pointer to an array of 3 ints.
- >
- > Hi Lawrence,
- >
- > I knew what it was, because I read AND understood that part of Deep C
- > Secrets. What I don't understand is where one would need something
- > like this. I can certainly use a pointer to an int array, but why
- > specifically an array of 3? I don't think this buys you anything
- > really. The three doesn't magically terminate the array like a nul.
- > It doesn't allocate any memory. So why and where and what is wrong
- > with just allocating it, if that is what you need?
- >
- > p = malloc(3 * sizeof(int));
-
- The usual reason for this is to handle multidimensional arrays where
- all but the first dimension is known at compile time. For example,
-
- int n;
- int (*p)[3];
- /* ... */
- p = malloc(n * sizeof *p);
-
- p can now be used as an array of [n][3] int (e.g., you can reference
- p[4][1] if 4 < n).
-
-
- Michael M Rubenstein
-